home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Devices & Hardware / NuBus⁄Slot Manager / Slot Tools / Data folder / Data (MPW 2.02) / Data.c next >
Encoding:
C/C++ Source or Header  |  1990-09-14  |  3.0 KB  |  109 lines  |  [TEXT/MPS ]

  1.  
  2. /**********************************************************************
  3.  *
  4.  * Copyright Apple Computer, Inc. 1986
  5.  * All Rights Reserved
  6.  *
  7.  *    Data            : This program reads the code segment 1 from
  8.  *                        the Resource file and and saves it, stripping.
  9.  *                        off code segment 0.
  10.  *
  11.  *    Author            : xxxxxx xxxxxx, July 30, 1986.
  12.  *
  13.  *    Mod History        : Nil.
  14.  *
  15.  **********************************************************************/
  16.                         
  17.  
  18. #include <stdio.h>
  19. #include <types.h>
  20. #include <osutils.h>
  21. #include <files.h>
  22. #include <resources.h>
  23. #include <memory.h>
  24. #include <errno.h>
  25.  
  26.  
  27.  
  28. pascal void _CalcCRC (SizeCode,CodePtr,crc)
  29. long        SizeCode;
  30. Ptr            CodePtr;
  31. long        *crc;
  32. extern;
  33.  
  34. /******************************************************************
  35.     Main
  36. *******************************************************************/
  37. main(argc,argv)
  38.  
  39. int      argc;
  40. char  *argv[];
  41.  
  42. {
  43.   short        refnum;
  44.   Handle    CodeHandle;        /* Handle to code resource */
  45.   short        IOR;            /* IO Result */
  46.   long        SizeCode;        /* Size of the code */
  47.   Ptr        CodePtr;        /* Pointer to the code */
  48.   long        crc;            /* the crc value */
  49.   int        FileDescript;    /* The file descriptor of the data file */
  50.   unsigned    NumBWritten;    /* Number of bytes written per write */
  51.   unsigned    Total;            /* Total number of bytes written */
  52.         
  53.   if (argc == 1)
  54.     {
  55.       fprintf(stderr,"### ERROR : No files specified.\n");
  56.       fprintf(stderr,"### SYNTAX: Data  rsrcFileName  DataFileName\n");
  57.       fprintf(stderr,"### DSCRPT: Copy code segment 1 to a data file.\n");
  58.     }
  59.   else if (argc != 3)
  60.     {
  61.       fprintf(stderr,"### ERROR : Wrong number of parameters specified.\n");
  62.       fprintf(stderr,"### SYNTAX: Data  rsrcFileName  DataFileName\n");
  63.       fprintf(stderr,"### DSCRPT: Copy code segment 1 to a data file.\n");
  64.     }
  65.   else
  66.     {
  67.       refnum = OpenResFile(argv[1]);
  68.       if (refnum < 0 )
  69.         fprintf(stderr,"### ERROR : Resource file: %s can't be opened. err = %d.\n",argv[1],refnum);
  70.       else
  71.         {
  72.            CodeHandle = GetResource('CODE',1);
  73.            HLock(CodeHandle);
  74.            IOR = ResError();
  75.            if (IOR != 0)
  76.              fprintf(stderr,"### ERROR : Code resource not available. Err = %d\n",errno);
  77.            else
  78.              {
  79.                SizeCode = GetHandleSize(CodeHandle);
  80.                SizeCode = SizeCode - 4;                                        /* Skip first 4 bytes (Resource header) */
  81.                CodePtr = (Ptr) ( ((long) *CodeHandle) & 0x0FFFFFF) + 4;        /* Skip first 4 bytes (Resource header) */
  82.         
  83.                FileDescript = creat(argv[2]);
  84.                if (FileDescript < 0)
  85.                  fprintf(stderr,"### ERROR : Data file: %s can't be opened. err = %d.\n",argv[2],errno);
  86.                else
  87.                  {
  88.                    Total = 0;
  89.                    while (Total < SizeCode)
  90.                      {
  91.                        NumBWritten = write(FileDescript,CodePtr,SizeCode);
  92.                        if (NumBWritten < 0)
  93.                          {
  94.                            fprintf(stderr,"### ERROR : Write err = %d.\n",errno);
  95.                            Total = SizeCode;
  96.                          }
  97.                        else
  98.                          Total = Total + NumBWritten;
  99.                      }
  100.                    close(FileDescript);
  101.                  }
  102.  
  103.                CloseResFile(refnum);
  104.              }
  105.         }
  106.     }
  107. }
  108.  
  109.